﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using Medicine.Util;
using Medicine.Entity;

namespace Medicine.Dao
{
    class MedicineDao
    {

        public List<Dictionary<String, Object>> query(String sql) {
            List<Dictionary<String,Object >> med_list= new List<Dictionary<String, Object>>();
            DataSet ds = DbHelper.query(sql);
            DataTable dt = ds.Tables[0];
           // MessageBox.Show(dt.Rows.Count.ToString());
            for (int i=0; i<dt.Rows.Count;i++) {
              
                Dictionary<String, Object> medicine = new Dictionary<String, Object>();
                medicine.Add("id",dt.Rows[i][0]);
                medicine.Add("name", dt.Rows[i][1]);
                medicine.Add("info", dt.Rows[i][2]);
                medicine.Add("price", dt.Rows[i][3]);
                medicine.Add("ison",dt.Rows[i][4]);
                med_list.Add(medicine);
            }
            return med_list;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="m">数据</param>
        public void delete(Medicin m)
        {
            String sql = "delete from medicine where id='" + m.Id + "'";
            DbHelper.insert(sql);
        }
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="m">user的实体</param>
        public void insert(Medicin m)
        {
            String sql = "insert into medicine(name,info,price,ison) values('" + m.Name + "','" + m.Information + "','" + m.Price + "','" + m.Ison + "')";
            DbHelper.insert(sql);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="m">数据</param>
        public void update(Medicin m)
        {
            String sql = "update medicine set name='" + m.Name + "',info='" + m.Information + "',price='" + m.Price + "',ison='" + m.Ison + "' where id='" + m.Id + "'";
            DbHelper.insert(sql);
        }
    }
}
